const express = require('express');
const app = express();
const formidable = require('express-formidable');
const path = require('path');
// 引入session模块
var session = require('express-session');

// 引入数据库模块
require('./model/index.js');

// formidable获取post参数，可以获取文件req.files，可以获取其他req.fields
app.use(formidable({
    encoding: 'utf-8',
    //图形文件存储在uploads里面
    uploadDir: path.join(__dirname, 'public', 'uploads'),
    multiples: true, // req.files to be arrays of files
    keepExtensions: true
}));


// session配置
// 目的1：存储登录信息，防止未登录跳转
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false
}));

// 模块化路由
require('./routes/index.js')(app);
app.listen(4001, () => {
    console.log('服务器连接成功！')
})